import type { NextRequest } from 'next/server';
import { issueClient } from "@/grpc";
import { project_issue_api } from "@/proto_gen_ts/proto/project_issue_api";

export interface ListIssueByIdRequest {
    shareId?: string;
    shareSecret?: string;
    issueIdList?: string[];
}

export async function POST(request: NextRequest): Promise<Response> {
    let reqData = await request.json() as ListIssueByIdRequest;

    return new Promise((resolve, reject) => {
        issueClient.listByShareAndId(new project_issue_api.ListByShareAndIdRequest({
            shareId: reqData.shareId,
            shareSecret: reqData.shareSecret,
            issueIdList: reqData.issueIdList,
        }), (error, response) => {
            if (error) {
                reject(error);
            } else {
                resolve(Response.json(response?.toObject()));
            }
        });
    });
}